//
//  XTBSearchBar.m
//  xietongbao
//
//  Created by LiuYihua on 2017/3/21.
//  Copyright © 2017年 sbq. All rights reserved.
//

#import "XTBSearchBar.h"
#import "UIView+Extension.h"

@implementation XTBSearchBar

+(instancetype)searchBarWithPlaceholder:(NSString *)placeholder backgroundImage:(UIImage *)image
{
    XTBSearchBar *searchBar = [[XTBSearchBar alloc]init];
    
    //创建搜索框对象
    searchBar.font = [UIFont systemFontOfSize:15];
    searchBar.placeholder = placeholder;
    searchBar.textAlignment = NSTextAlignmentCenter;
    searchBar.background  = image;
    [searchBar setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    
    //通过init创建初始化绝大部分控件，都是没有尺寸的
    UIImageView * Icon = [[UIImageView alloc]init];
    Icon.image = [UIImage imageNamed:@"search_icon"];
    Icon.width = 30;
    Icon.height = 30;
    Icon.contentMode = UIViewContentModeCenter;
    searchBar.leftView = Icon;
    searchBar.leftViewMode = UITextFieldViewModeAlways;
    
    return searchBar;
}


@end
